package com.itheima.observer;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zzw
 * @date 2025/10/25
 * @description 观察者模式（具体主题类）
 */
public class SubscriptionSubject implements Subject {

    // 储存订阅微信公众号的用户
    private final List<Observer> weixinUserList = new ArrayList<>();

    @Override
    public void attach(Observer observer) {
        weixinUserList.add(observer);
    }

    @Override
    public void detach(Observer observer) {
        weixinUserList.remove(observer);
    }

    @Override
    public void notify(String message) {
        for (Observer observer : weixinUserList) {
            observer.update(message);
        }
    }
}
